<?=view('admin.common.header')?>
<style>
    .table>tbody>tr>td {vertical-align: middle;}
</style>
<form id="modifyform" action method="post">
<table class="table">
    <tr>
        <td>名称</td>
        <td>
            <input type="text" name="name" class="form-control" required="required"/>
        </td>
    </tr>
    <tr>
        <td>价格</td>
        <td>
            <input type="number" name="price" class="form-control" required="required"/>
        </td>
    </tr>
    <tr>
        <td>平台优惠</td>
        <td>
            <input type="number" name="pfav" class="form-control" required="required"/>
        </td>
    </tr>
    <tr>
        <td>描述</td>
        <td>
            <textarea class="form-control" name="desc" required="required"></textarea>
        </td>
    </tr>
    <tr>
        <td>类型</td>
        <td>
            <select name="ptype" class="form-control" required="required">
                <?php foreach(Illuminate\Support\Facades\Config::get('global.site.ptype') as $key => $val): ?>
                <option value="<?= $key?>"><?= $val ?></option>
                <?php endforeach; ?>
            </select>
        </td>
    </tr>
    <tr>
        <td>地区</td>
        <td>
            <select name="area" class="form-control" required="required">
                <?php foreach($area as $val): ?>
                <option value="<?= $val->id?>"><?= $val->name ?></option>
                <?php endforeach; ?>
            </select>
        </td>
    </tr>
    <tr>
        <td>产品属于</td>
        <td>
            <select name="pcateid" class="form-control" required="required">
                <?php foreach($pcate as $val): ?>
                <option value="<?= $val->id?>"><?= $val->name?></option>
                <?php endforeach; ?>
            </select>
        </td>
    </tr>
    <tr>
        <td>产品时长</td>
        <td>
            <input type="text" name="lot" class="form-control" required="required"/>
        </td>
    </tr>
    <tr>
        <td>产品排序</td>
        <td>
            <input type="text" name="sort" class="form-control" required="required"/>
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <button class="btn btn-primary form-control eveAdd">添加商品</button>
        </td>
    </tr>
</table>
    <script>
        $('.eveAdd').click(function(){
            var name = $('input[name="name"]').val(), price = $('input[name="price"]').val(), desc = $('textarea[name="desc"]').val(), ptype = $('select[name="ptype"]').val();
            if (name == '') {
                layer.msg('产品名称不能为空');
                return false;
            }
            if (price == '') {
                layer.msg('产品价格不能为空');
                return false;
            }
            if (desc == '') {
                layer.msg('产品描述不能为空');
                return false;
            }
            if (ptype == '') {
                layer.msg('产品类型不能为空');
                return false;
            }
            $("#modifyform").ajaxSubmit(function(data){
                layer.msg(data.info);
                if (data.status == 1) {
                    window.parent.location.reload();
                }
            });
            return false;
        })
    </script>
</body>
</html>